﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.Common;
using LGCourt.Logic.BLL;
using LGCourt.Logic.NBL.DBEntities;
using KMFrame.Permission.Util;


namespace lgweb.control.inside.department
{
    public partial class header : System.Web.UI.UserControl
    {
        private string deptCode = "";
        private string deptID = "0";
        private string menu = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (!SessionBox.CheckUserSession())
                {
                    Response.Redirect("/inside/login.aspx");
                }
                DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateHandler dh = new DateHandler(dt);
                this.header_date.InnerHtml = "今天是" + DateTime.Now.ToLongDateString() + " 星期" + dh.weekValue + " 农历" + dh.lunarMonthValue + dh.lunarDayValue;
                //GetUserInfo();
                this.menu = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "0" : Request.QueryString["cate"];
                this.deptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"].ToString();
                this.deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "" : Request.QueryString["Code"].ToString();
                SetMenu();
                SetClassName();
            }
        }

        private void SetMenu()
        {
            this.hdindex.HRef = string.Format("/inside/department/index.aspx?cate=0&deptid={0}&Code={1}", deptID, deptCode);
            this.hdoffice.HRef = string.Format("/inside/department/notice.aspx?cate=1&deptid={0}&Code={1}", deptID, deptCode);
            this.hdinfo.HRef = string.Format("/inside/department/list.aspx?cate=2&deptid={0}&Code={1}", deptID, deptCode);
            this.hdnews.HRef = string.Format("/inside/department/list.aspx?cate=3&deptid={0}&Code={1}", deptID, deptCode);
            this.hdwenhua.HRef = string.Format("/inside/department/list.aspx?cate=4&deptid={0}&Code={1}", deptID, deptCode);
            this.hdshiping.HRef = string.Format("/inside/department/list.aspx?cate=5&deptid={0}&Code={1}", deptID, deptCode);

            switch (this.menu)
            {
                case "0":
                    this.hdindex.Attributes.Add("class", "current");                    
                    break;
                case "1":
                    this.hdoffice.Attributes.Add("class", "current");                   
                    break;
                case "2":
                    this.hdinfo.Attributes.Add("class", "current");
                    break;
                case "3":
                    this.hdnews.Attributes.Add("class", "current");                    
                    break;                
                case "4":
                    this.hdwenhua.Attributes.Add("class", "current");                    
                    break;
                case "5":
                    this.hdshiping.Attributes.Add("class", "current");                   
                    break;
                default:
                    this.hdindex.Attributes.Add("class", "current");                    
                    break;
            }
        }
        private void SetClassName()
        {
            ColInfo colInfoBLL = new ColInfo();
            string detpName = "";
            if (deptID == "0")
            {
                DeptClassCondition param = new DeptClassCondition();
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(deptCode);
                if (department != null)
                {
                    detpName = department.Name;
                }
                //根据名称取部门ID
                param.Source = detpName;
                param.Name = "部门";
                V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
                deptID = deptInfo == null ? "0" : deptInfo.ID.GetValueOrDefault(0).ToString();
            }
            
            //部门信息            
            DeptCondition deptParam = new DeptCondition();
            deptParam.DeptID = int.Parse(deptID);            

            //取栏目
            List<IF_DeptClass> deptClassList = colInfoBLL.GetDeptClassList(deptParam);
            this.hdinfo.InnerText = deptClassList.Count >= 1 ? deptClassList[0].ClassName : "重要文件";
            this.hdnews.InnerText = deptClassList.Count >= 2 ? deptClassList[1].ClassName : "政治学习";
            this.hdwenhua.InnerText = deptClassList.Count >= 3 ? deptClassList[2].ClassName : "部门风采";
            this.hdshiping.InnerText = deptClassList.Count >= 4 ? deptClassList[3].ClassName : "办公助手";
        }
    }
}
